﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using SharedGenomics.Core;
using SharedGenomics.Workbench.PresentationModel;

namespace SharedGenomics.Workbench.Views.WindowsForms
{
    public partial class EditUserMarkerView : View, IEditUserMarkerView
    {
        public EditUserMarkerView()
        {
            InitializeComponent();
            this.btUpdate.Click += (o, e) => { this.EditEnded.Raise(this); };
        }

        private void EditRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            //this.OnEditingRsNumberChanged(EventArgs.Empty);
        }

        public SnpMarkerInfo Marker
        {
            get
            {
                return this.markerBindingSource.DataSource as SnpMarkerInfo;
            }
            set
            {
                //if (value == null)
                //    this.markerBindingSource.Clear();
                //else
                //    this.markerBindingSource.DataSource = value;
            }
        }

        public bool EndEditEnabled
        {
            set { this.btUpdate.Enabled = value; }
        }

        public bool EditingRsNumber
        {
            get { return this.rbRsNumber.Checked; }
            set
            {
                this.rbRsNumber.Checked = value;
                this.rbDetails.Checked = !value;
            }
        }

        public bool IsRsNumberEnabled
        {
            set { this.txtRsNumber.Enabled = value; }
        }

        public bool IsChromosomeEnabled
        {
            set { this.txtChromosome.Enabled = value; }
        }

        public bool IsPositionEnabled
        {
            set { this.txtPosition.Enabled = value; }
        }

        public string ServiceMessage
        {
            set { this.txtServiceError.Text = value ?? String.Empty; }
        }

        public EditUserMarkerPTO PTO
        {
            set { this.markerBindingSource.DataSource = value; }
        }

        protected override IEnumerable<Binding> ValidatedDataBindings
        {
            get { return this.markerBindingSource.CurrencyManager.Bindings.Cast<Binding>(); }
        }

        public event EventHandler EditEnded;
        public event EventHandler EditingRsNumberChanged;
    }
}
